﻿using UnityEngine;
using UnityEngine.InputSystem;



public class InputHandler : MonoBehaviour
{
    // 输入事件
    public event System.Action<Vector3> OnMove;
    public event System.Action OnSprintPressed;
    public event System.Action OnSprintReleased;
    public event System.Action OnCrouchToggled;
    public event System.Action OnInteractionToggled;

    private PlayerInput _playerInput;

    void Awake()
    {
        _playerInput = GetComponent<PlayerInput>();

        // 绑定输入回调
        _playerInput.actions["Move"].performed += ctx => OnMove?.Invoke(ctx.ReadValue<Vector2>());
        _playerInput.actions["Sprint"].started += _ => OnSprintPressed?.Invoke();
        _playerInput.actions["Sprint"].canceled += _ => OnSprintReleased?.Invoke();
        _playerInput.actions["Crouch"].performed += _ => OnCrouchToggled?.Invoke();
        _playerInput.actions["Interaction"].started += _ => OnInteractionToggled?.Invoke();
    }

    private void Update()
    {
        OnMove?.Invoke(_playerInput.actions["Move"].ReadValue<Vector3>());
    }



}